
let {api} = require ("./api.js")
// 获取轮播图数据
let getBannerList = () =>{
  return new Promise((resolve,rejects) =>{
    wx.request({
      url: `${api}/banner?type=2`,
      method:"GET",
      success:(res) =>{
        resolve(res)
      },
      fail:(err) =>{
        rejects(err)
      }
    })
  })
}
// 获取热门榜单数据
let getHotList = ()=>{
  return new Promise((resolve,rejects) =>{
    wx.request({
      url: `${api}/toplist/detail`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err) =>{
        rejects(err)
      }
    })
  })
}
// 获取榜单详情
let getHotInfo = (id) =>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/playlist/detail?id=${id}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 推荐新的新的音乐的数据
let getNewMic = () =>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/personalized/newsong`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 获取音乐播放地址
let getMicUrl = (id) =>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/song/url?id=${id}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 获取歌词
let getLyric = (id)=>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/lyric?id=${id}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 获取热门歌手
let getSinggerList = (initial)=>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/artist/list?type=-1&area=-1&initial=${initial}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 获取歌手详情
let getSinggerTop = (id)=>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/artist/top/song?id=${id}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 获取热门搜索
let getSearchList =()=>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/search/hot`,
      method:"GET",
      success:(res)=>{
          resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 搜索音乐
let getSearch = (keywords)=>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/search/suggest?keywords=${keywords}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
// 获取音乐详情
let getMIc = (ids)=>{
  return new Promise((resolve,rejects)=>{
    wx.request({
      url: `${api}/song/detail?ids=${ids}`,
      method:"GET",
      success:(res)=>{
        resolve(res)
      },
      fail:(err)=>{
        rejects(err)
      }
    })
  })
}
module.exports={
  getBannerList,
  getHotList,
  getHotInfo,
  getNewMic,
  getMicUrl,
  getLyric,
  getSinggerList,
  getSinggerTop,
  getSearchList,
  getSearch,
  getMIc
  
}